home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 18 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  75 lines

  1. Path: tank.news.pipex.net!pipex!demon!fredblog.demon.co.uk
  2. From: mark@fredblog.demon.co.uk (Mark Winfield)
  3. Newsgroups: comp.lang.c
  4. Subject: What's so different about 2-D arrays???
  5. Date: Sun, 31 Dec 1995 23:18:43 GMT
  6. Organization: - none -
  7. Message-ID: <820451938.20697@fredblog.demon.co.uk>
  8. Reply-To: mark@fredblog.demon.co.uk
  9. NNTP-Posting-Host: fredblog.demon.co.uk
  10. X-NNTP-Posting-Host: fredblog.demon.co.uk
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. I have been teaching myself 'C' over the last month.  Just before Xmas
  14. I thought that I had it worked out and that all I had to do was
  15. practice.  I decided to write a program that would record chess games,
  16. it would allow move branching as well.  I decided upon this because it
  17. should use everything I have learnt except DOS calls.
  18. Now for the problem,
  19.  
  20. //My own chess recorder program
  21.  
  22. #include <stdio.h>
  23. #include <ctype.h>
  24.  
  25. /*Prototypes*/
  26. void setup(char pos[8][8]);   
  27.  
  28.  
  29. void main()
  30. {
  31. char pos[8][8];
  32.  
  33.     setup(pos);
  34.  
  35.  
  36.     printf("\nWell Done!!");
  37. }
  38.  
  39. void setup(char pos[8][8])
  40. {
  41. int x,y;    
  42.  
  43.     pos[1][8]=pos[8][8]='r';
  44.     pos[2][8]=pos[7][8]='n';
  45.     pos[3][8]=pos[6][8]='b';
  46.  
  47.     pos[1][1]=pos[8][1]='R';
  48.     pos[2][1]=pos[7][1]='N';
  49.     pos[3][1]=pos[6][1]='B';
  50.  
  51.     for(x=1;x<9;x++){
  52.         pos[x][7]='a';
  53.         pos[x][2]='A';
  54.  
  55.         for(y=3;y<7;y++)
  56.             pos[x][y]=' ';
  57.     }
  58.  
  59.     pos[4][8]='q';
  60.     pos[5][8]='k';
  61.  
  62.     pos[4][1]='Q';
  63.     pos[5][1]='K';
  64. }
  65.  
  66. This program does not work with a '.c' or '.cpp' extension.  If I run
  67. the program from dos I get well done and then something about NULL
  68. pointers and the program hangs, so I have to reset. And if I run the
  69. program from within the TURBO C++ enviroment the program hangs after
  70. printing well done.
  71.  
  72. I have written a similar program since, as a test, which uses a 1-D
  73. array with no problems.  Can someone help me with this problem.
  74.  
  75.